package com.farm.chain;

import com.farm.strategy.AvoidObstacleStrategy;
import com.farm.strategy.PathPlanner;

// 具体处理器类
public class ObstacleHandler implements EmergencyHandler {
    private EmergencyHandler nextHandler;

    @Override
    public void setNextHandler(EmergencyHandler nextHandler) {
        this.nextHandler = nextHandler;
    }

    @Override
    public void handleRequest(EmergencyRequest request, String machineName) {
        if (request.getType().equals("OBSTACLE")) {
            System.out.println(machineName + "障碍物处理器处理: " + request.getMessage());
            System.out.println(machineName + "执行避障操作: 停止前进，重新规划路径：");
            //使用策略模式重新规划路径
            PathPlanner planner = new PathPlanner();
            planner.setStrategy(new AvoidObstacleStrategy());
            planner.executePathPlanning(machineName);
        } else if (nextHandler != null) {
            nextHandler.handleRequest(request, machineName);
        }
    }
}
